﻿#ifndef JZWEB_SERBER_H_
#define JZWEB_SERBER_H_

#include <QObject>
#include <QMap>
#include <QTcpServer>
#include <QTcpSocket>
#include "JZWebPage.h"
#include "JZWebRequest.h"
#include "JZWebResponse.h"

class JZWebServer : public QObject
{
	Q_OBJECT

public:
	JZWebServer(QObject *parent = nullptr);
	~JZWebServer();

	bool start(int port);
	void stop();

	void addPage(QString url,JZWebPage *page);

protected slots:
	void onNewConnection();

protected:
	class NetMessage
	{
	public:
	};

    void processClient(QTcpSocket *socket);
	void onHttpRequest(const HttpRequest& req, HttpResponse &res);

	QTcpServer* m_server;
	QMap<QString, JZWebPage*> m_pages;
	QMap<int, JZWebContextPtr> m_contexts;
	QMap<QTcpSocket*, JZWebRequestPtr> m_requests;
};



#endif // !JZWEB_SERBER_H_
